package com.example.zzl.view.fragment.ShareOrderFragment.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.zzl.R;
import com.example.zzl.view.fragment.ShareOrderFragment.disan.ListUtils;
import com.example.zzl.view.fragment.ShareOrderFragment.fragment.Mylist;
import com.example.zzl.view.fragment.ShareOrderFragment.model.Infor;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/2/11.
 */
public class InforAdapter extends BaseAdapter{

    private Context context;
    private List<Infor> olist;
    private List<Object>list;
    private List<String> hehe;

    public InforAdapter(Context context, List<Infor> olist) {
        this.context = context;
        this.olist = olist;
        list=new ArrayList<>();
        hehe=new ArrayList();
    }

    @Override
    public void notifyDataSetChanged() {
        Object object=olist.get(0);
        if (object instanceof Infor){
            list.add(((Infor) object).ImageTags);

            list.add(((Infor) object).InfoContent);

            hehe.add(((Infor) object).InfoTitle);
            hehe.add(((Infor) object).CommodityPrice);
            hehe.add(((Infor) object).CMainImage);

            list.add(hehe);

            list.add(((Infor) object).reviewinfolist.get(0).infolist);

        }



        super.notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        Log.e("123321",list.size()+"");
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getViewTypeCount() {
        return 2;
    }

    @Override
    public int getItemViewType(int position) {
        Object o=list.get(position);
//        List o1 = (List) o;
//        Object o2 = o1.get(0);
        if (o instanceof String){


                return 1;//tv
            }else {
                return 0;
            }
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
Object o=list.get(position);
        if (convertView==null){
            vh=new ViewHolder();
            if (getItemViewType(position)==0){

                convertView=View.inflate(context, R.layout.listview,null);
                vh.lv1=(Mylist) convertView.findViewById(R.id.myl);
                vh.lv2=(Mylist) convertView.findViewById(R.id.myl);
                vh.lv3=(Mylist) convertView.findViewById(R.id.myl);

                convertView.setTag(vh);
            }else if (getItemViewType(position)==1){
                convertView=View.inflate(context, R.layout.tv,null);

                vh.tv=(TextView)convertView.findViewById(R.id.tt);
                convertView.setTag(vh);

            }
        }else {
            vh=(ViewHolder)convertView.getTag();
        }

        if (getItemViewType(position)==0){

            if (o instanceof List){


                Object o1 = ((List) o).get(0);
                if (o1 instanceof Infor.ImageTagsBean){

                    List<Infor.ImageTagsBean> oo=(List<Infor.ImageTagsBean>)o;
//                    List<Infor.ImageTagsBean> l1=new ArrayList<>();
//                    l1.add(iitb);
                  //  Log.e("qweeq", l1.size()+"");

                    TuAdapter tuAdapter=new TuAdapter(context,oo);
                    vh.lv1.setAdapter(tuAdapter);
                    ListUtils.setListViewHeight(vh.lv1);


                }
                else if (o1 instanceof String){
                    List<String> ll=(List<String>)o;
                    GuangGaoAdapter aadapter=new GuangGaoAdapter(context,ll);
                    vh.lv2.setAdapter(aadapter);
                    ListUtils.setListViewHeight(vh.lv2);

                }else if (o1 instanceof Infor.ReviewinfolistBean.InfolistBean){
                    List<Infor.ReviewinfolistBean.InfolistBean>iri=(List<Infor.ReviewinfolistBean.InfolistBean>)o;
                    Log.e( "getView: ", iri.size()+"");
                    HeAdapter hadapter=new HeAdapter(context,iri);
                    vh.lv3.setAdapter(hadapter);
                    ListUtils.setListViewHeight(vh.lv3);

                }


            }

        }else if (getItemViewType(position)==1){
            if (o instanceof String){
                String a=(String)o;
                vh.tv.setText(a);
            }

        }

        return convertView;
    }
   class ViewHolder{
       Mylist lv1,lv2,lv3;
       TextView tv;
    }
}
